<template>
    <div>

    </div>
</template>

<script>
import { loginByToken, getLoginUserInfo } from "@/api/login";
export default {
    name: "thirdpartyLogin",
    data() {
        return {
            token: "",
        }
    },
    mounted() {
        var redirect = this.getUrlKey("redirect");
        this.token = this.getUrlKey("token");
        loginByToken({ token: this.token }).then(resp => {
            if (resp.status == 0) {
                this.$store.dispatch("user/thirdpartyLogin", resp.data.token).then(() => {
                    getLoginUserInfo().then(response => {
                        if (response.status == 0) {
                            this.$store.dispatch("user/setUserInfo", response.data).then(() => {
                                if (redirect) {
                                    this.$router.push({ path: redirect });
                                } else {
                                    this.$router.push({ path: "/" });
                                }
                            });
                        } else {
                            this.$antMessage.warning(response.message);
                        }
                    });
                });
            } else {
                this.$antMessage.warning(resp.message);
                this.$router.push({ path: "/login" });
            }
        });
    },
    methods: {
        getUrlKey: function (name) {
            return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null;
        }
    }
}
</script>

<style lang="scss">
</style>